今天要來講解loc語法的基礎用法,
輸出值的資料結構為Series。
首先,先建立一個DataFrame結構的資料,
或是有匯入的資料轉成DataFrame結構也行,
這次的資料結構以JSON格式做轉換,
以資料中的A、B、C作為索引。
這邊為了方便對照,先印出完整的資料來看。
scoresData = {
    "Chinese":
    {
        "A": 54,
        "B": 76,
        "C": 66,
    },
    "English":
    {
        "A": 61,
        "B": 97,
        "C": 75,
    },
    "Math":
    {
        "A": 71,
        "B": 82,
        "C": 67,
    }
}
scores = pd.DataFrame(scoresData)
print(scores)
印出資料如下,
對照可看出A、B、C三人在三個科目上的成績分別是多少。
   Chinese  English  Math
A       54       61    71
B       76       97    82
C       66       75    67
介紹loc語法,
在資料後加上.loc["索引值"],
使用方式如下,
這邊選擇取得索引值A的資料。
print(scores.loc["A"])
印出資料如下,
資料結構為Series。
Chinese    54
English    61
Math       71
Name: A, dtype: int64
對照完整的表可以找出索引值A的各科目成績,
也就是輸出的值。
今天學到了loc語法的使用,
可以用指定索引值來找出其對應的所有資料,
明天來談談iloc語法的基礎用法,
可以稍微來比較一下這兩者的差異